<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'>
    <meta name='renderer' content='webkit|ie-comp|ie-stand'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
    <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>
    <meta http-equiv='Cache-Control' content='no-siteapp'/>
    <title>回款计划表</title>
    <script src='../../../static/kaige/js/szload.js'></script>
</head>

<body>
<div class='kaige-body'>
    <table class='layui-table' id='pageTable' lay-filter='pageTable' lay-size='sm'></table>
    <input type='hidden' name='keywordsCache' value='{}'/>
</div>

<script>
    load_init_js([
        szoapcpath + '/static/kaige/js/date.js',
        szoapcpath + '/static/kaige/js/search.js',
        szoapcpath + '/static/kaige/js/xm-select.js'
    ], function () {
        layui.config({
            base: szoapcpath + '/static/kaige/layuiextend/'
        }).use(['element', 'table', 'form', 'layer', 'kaige', 'lvybtpl', 'laydate'], function () {
            var element = layui.element,
                layer = layui.layer,
                table = layui.table,
                form = layui.form,
                lvybtpl = layui.lvybtpl,
                kaige = layui.kaige,
                laydate = layui.laydate,
                $ = layui.$;

            window.kaige_page = {
                logout_url: '/index/logout',
                welcome: './pages/welcome.html',
                menus: [],
                leftmenu: [],
            };
            window.pagedict = parent.window.kaige_page.dict || {};

            form.render();
            kaige.table({
                elem: '#pageTable',
                url: '/crm.receivables_plan/index',
                id: 'pageTable',
                toolbar: '#dtoolbar',
                defaultToolbar: ['filter'],
                cols: [[
                    {field: 'id', title: '', align: 'center'},
                    {field: 'num', title: '期数', align: 'center'},
                    {field: 'contract_id', title: '合同编号', align: 'center'},
                    {field: 'customer_id', title: '客户名称', align: 'center'},
                    {field: 'money', title: '计划回款金额', align: 'center'},
                    {field: 'return_date', title: '计划回款日期', align: 'center'},
                    {field: 'return_type_id', title: '计划回款方式', align: 'center', templet: '#return_type_id_name'},
                    {field: 'remind', title: '提前几天提醒', align: 'center'},
                    {field: 'remarks', title: '备注', align: 'center'},
                    {title: '操作', toolbar: '#dtrbar', align: 'center', width: 150, fixed: 'right'}
                ]]
            });

            //列表-监听表头工具栏事件dtoolbar
            table.on('toolbar(pageTable)', function (obj) {
                switch (obj.event) {
                    case 'btn-add':
                        btnadd();
                        break;
                }
            });

            //列表-监听单元格行工具事件dtrbar
            table.on('tool(pageTable)', function (obj) {
                var that = this;
                var data = obj.data;
                switch (obj.event) {
                    case 'edit':
                        baredit(data);
                        break;
                    case 'del':
                        bardel(data);
                        break;
                }
            });


            window.addEditData = function () {
                var customer_id = $('#customer_id').val();
                lvybtpl.xmSelect({
                    url: '/select/Customer'
                    , id: 'customer_id'
                    , getData: {automatch: 1}
                    , values: [customer_id]
                    , setafter: function () {
                        var customer_id = $('#customer_id').val();
                        var contract_id = $('#contract_id').val();
                        lvybtpl.xmSelect({
                            url: '/select/Contract'
                            , id: 'contract_id'
                            , getData: {automatch: 1, customer_id: customer_id}
                            , values: [contract_id]
                        });
                    }
                });
                $('#getMoney').on('click', function () {
                    var contract_id = $('#contract_id').val();
                    if (contract_id != undefined && contract_id != '') {
                        szoa.get('/crm.contract/edit', {id: contract_id}, function (res) {
                            if (res.status) {
                                $('#money').val(res.data.money);
                            } else {
                                layer.msg(res.msg)
                            }
                        })
                    } else {
                        layer.msg('请选择合同!')
                    }

                });

                laydate.render({
                    elem: '#return_date'
                    , type: 'date'
                });
            }

            //添加
            function btnadd() {
                kaige.form({
                    url: '/crm.receivables_plan/add',
                    data: {},
                    id: 'kaige',
                    area: ['750px', '450px'],
                    title: '<i class=\'layui-icon layui-icon-add-circle\'></i> 添加 - 回款计划表',
                    tablelayid: 'pageTable',
                    overflow: false,
                    encode: 1,
                    callbefore: function (layero, index) {
                        addEditData();
                    }
                });
            }

            //编辑
            function baredit(d) {
                kaige.form({
                    url: '/crm.receivables_plan/edit',
                    data: {id: d.id},
                    id: 'kaige',
                    area: ['750px', '450px'],
                    title: '<i class=\'layui-icon layui-icon-edit\'></i> 编辑 - 回款计划表',
                    tablelayid: 'pageTable',
                    overflow: false,
                    encode: 1,
                    callbefore: function (layero, index) {
                        addEditData();
                    },
                });
            }

            //删除
            function bardel(d) {
                layer.confirm('您确定删除吗？', {
                    title: '<i class=\'layui-icon layui-icon-delete\'></i> 删除确认',
                    btn: ['确认', '取消']
                }, function () {
                    $.post('/crm.receivables_plan/del', {id: d.id}, function (res) {
                        res.status && table.reload('pageTable');
                        layer.msg(res.msg);
                    });
                });
            };

        });
    });
</script>
<script type='text/html' id='dtrbar'>
    <div class='layui-btn-group'>
        <button class='layui-btn layui-btn-xs' lay-event='edit' title='编辑'><i class='layui-icon layui-icon-edit'></i>
        </button>
        <button class='layui-btn layui-btn-xs' lay-event='del' title='删除'><i class='layui-icon layui-icon-delete'></i>
        </button>
    </div>
</script>
<script type='text/html' id='dtoolbar'>
    <div class='layui-btn-container layui-form filter-form' lay-filter='searchform'>
        <div class='layui-btn-group'>
            <button type='button' class='layui-btn layui-btn-sm' lay-event='btn-add' style='margin-top:2px;'><i
                    class='layui-icon layui-icon-add-circle'></i> 添加
            </button>
        </div>
    </div>
</script>
<script type='text/html' id='return_type_id_name'>
    {{# for(var ipd in pagedict.return_type){ }}
    {{# if(d.return_type_id ==ipd){ }}
    <span>{{ pagedict.return_type[ipd] }}</span>
    {{# } }}
    {{# } }}
</script>
<script type='text/html' id='kaige_form_html'>
    <form class='layui-form layui-form-pane kaige-body-form' style='padding: 5px;' lay-filter='kaige_form_lay_filter'>
        {{# if(d.id){ }}
        <input type='hidden' name='id' value='{{ d.id }}'/>
        {{# } }}
        <div class='layui-form-item'>
            <label class='layui-form-label'>期数</label>
            <div class='layui-input-block'>
                <input name='num' value='{{ d.num || '' }}' class='layui-input' type='number'>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>客户ID</label>
            <div class='layui-input-inline'>
                <div id='customer_id_select_box'></div>
                <input id='customer_id' name='customer_id' value='{{ d.customer_id || '' }}' type='hidden'>
                <input id='customer_id_name' name='customer_id_name' value='{{ d.customer_id_name || '' }}'
                type='hidden'>
            </div>
            <label class='layui-form-label'>合同ID</label>
            <div class='layui-input-inline'>
                <div id='contract_id_select_box'></div>
                <input id='contract_id' name='contract_id' value='{{ d.contract_id || '' }}' type='hidden'>
                <input id='contract_id_name' name='contract_id_name' value='{{ d.contract_id_name || '' }}'
                type='hidden'>
            </div>
        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>回款金额</label>
            <div class='layui-input-inline'>
                <input id='money' name='money' value='{{ d.money || '' }}' class='layui-input' type='text' readonly>
                <button id='getMoney' type='button' class='layui-btn layui-btn-sm'
                        style='position: absolute;bottom: 0px;height: 37px;left: 144px;'>获取
                </button>
            </div>
            <label class='layui-form-label'>回款方式</label>
            <div class='layui-input-inline'>
                <select name='return_type_id' lay-verify='required'>
                    {{# lay.each(pagedict.return_type,function(index,item){
                    if(index == ''){
                    top.layer.msg('系统字典->跟进类型未配置完成，值不能为空');
                    }
                    }}
                    <option value='{{ index }}' {{ d.level== index ?
                    'selected' :'' }}>{{ item }}</option>{{# }) }}
                </select>
            </div>

        </div>
        <div class='layui-form-item'>
            <label class='layui-form-label'>回款日期</label>
            <div class='layui-input-inline'>
                <input id='return_date' name='return_date' value='{{ d.return_date || '' }}' class='layui-input'
                type='text'>
            </div>
            <label class='layui-form-label'>提醒</label>
            <div class='layui-input-inline'>
                <input name='remind' value='{{ d.remind || '' }}' class='layui-input' type='number'
                placeholder='提前几天提醒'>
            </div>
        </div>

        <div class='layui-form-item layui-hide'>
            <button class='layui-hide' lay-submit="" id='kaige_form_btn_save' lay-filter='kaige_form_btn_save'>保存数据
            </button>
        </div>
    </form>
</script>
</body>

</html>